import React from "react";
import axios from "axios";
import { SearchOutlined } from '@ant-design/icons';
import { Button, Input, Space, Table } from 'antd';
import Highlighter from 'react-highlight-words';
axios.defaults.timeout = 6000;
class SuiS extends React.Component {
  constructor() {
    super();
    this.state = {
      a: [],
      b: [],
      c: [],
      d: [],
      e: [],
      f: [],
      g: [],
      h: [],
      i: [],
      j: [],
      k:[],
      usa: [],
      uaa: [],
      usb:[],
      uab:[],
      uzb:[],
      usc:[],
      uac:[],
      uzb:[],
      uzc:[],
      uad:[],
      usd:[],
      uzd:[],
      m:[],
      usm: [],
      uam: [],
      usm:[],
     xa:[],
     usxa: [],
      uaxa: [],
      usxa:[],
         searchText:"",
      searchedColumn:"",

    };
      this.searchInput= React.createRef(null)
  }

  /* 
  a= 蔡正平= 43.153.65.89
  b= 郭发展=  43.153.79.98
  c = 郭蒋平= 43.135.172.133
  d  = 郭凯鸿6=43.152.217.89
  e=  郭煜尚7= 43.158.210.229
  f= 李瑶瑶2= 43.158.194.253
  g=  潘秀丽1= 43.134.231.239
  h=    彭香兰8=  43.135.155.149
  i= 叶凤华3=43.156.231.195
  j= 沈信义5=119.28.250.113
  k=刘爱绿4=119.28.250.113
  */
  componentDidMount() {
    // 账号1的高度a
    axios
      .get("http://43.153.68.26:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          a: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ a: "0" });
      });
      //获取uuid号
      axios
      .get("/node-selection-stats?uuid=c432d4ae-d3b5-4027-a39c-e0b46c3467ae")
      .then((res) => {
        
        this.setState({
          usb: JSON.stringify(res.data.stats.user_start_date),
        });
        this.setState({
          uab: JSON.stringify(res.data.stats.date_added),
        });
        this.setState({
          uzb: JSON.stringify(res.data.stats.availability),

        });
        
      })
      .catch((err) => {
        this.setState({ uab: "无效uuid号" });
      });

    //账号2高度b
    axios
      .get("http://43.135.166.80:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          b: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ b: "0" });
      });
    //账号3高度c
    axios
      .get("http://43.153.79.135:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          c: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ c: "0" });
      });
    //账号4高度d
    axios
      .get("http://170.106.194.145:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          d: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ d: "0" });
      });
    //账号5高度e
    axios
      .get("http://43.153.120.159:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          e: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ e: "0" });
      });
    //账号6高度f
    axios
      .get("http://43.153.15.235:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          f: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ f: "0" });
      });
    //账号7高度g
    axios
      .get("http://43.135.153.93:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          g: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ g: "0" });
      });
    //账号8高度h
    axios
      .get("http://43.156.17.198:31401")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          h: res.data.core_latest_ledger,
        });
      })
      .catch((err) => {
        this.setState({ h: "0" });
      });
      //  获取uuid
      axios
  .get("/node-selection-stats?uuid=cc0701c3-7749-42b9-8c63-8c1a4fb5d8cd")
      .then((res) => {
        console.log(res.data.core_latest_ledger);
        this.setState({
          uaa: JSON.stringify(res.data.stats.date_added),
          usa: JSON.stringify(res.data.stats.user_start_date),

        });
          this.setState({
          uza: JSON.stringify(res.data.stats.availability),

        });

      })
      .catch((err) => {
        this.setState({ uaa: "无效uuid号" });
      });
      //账号9高度i
    axios
    .get("http://129.226.90.234:31401")
    .then((res) => {
      console.log(res.data.core_latest_ledger);
      this.setState({
        i: res.data.core_latest_ledger,
      });
    })
    .catch((err) => {
      this.setState({ i: "0" });
    });
    //  获取uuid
    axios
.get("/node-selection-stats?uuid=ec2b1ac8-347a-465d-8ae2-4a4e71c240ed")
    .then((res) => {
      console.log(res.data.core_latest_ledger);
      this.setState({
        uac: JSON.stringify(res.data.stats.date_added),
        usc: JSON.stringify(res.data.stats.user_start_date),

      });
        this.setState({
          uzc: JSON.stringify(res.data.stats.availability),

        });

    })
    .catch((err) => {
      this.setState({ uac: "无效uuid号" });
    });

    //账号10高度k
    axios
    .get("http://43.153.114.43:31401")
    .then((res) => {
      console.log(res.data.core_latest_ledger);
      this.setState({
        k: res.data.core_latest_ledger,
      });
    })
    .catch((err) => {
      this.setState({ k: "0" });
    });
    //  获取uuid
    axios
.get("/node-selection-stats?uuid=dcb75a14-23d0-4522-b395-99115127529c")
    .then((res) => {
      
      this.setState({
        uad: JSON.stringify(res.data.stats.date_added),
        usd: JSON.stringify(res.data.stats.user_start_date),

      });
        this.setState({
          uzd: JSON.stringify(res.data.stats.availability),

        });

    })
    .catch((err) => {
      this.setState({ uad: "无效uuid号" });
    });
    //账号11高度m
    axios
    .get("http://43.153.49.98:31401")
    .then((res) => {
      console.log(res.data.core_latest_ledger);
      this.setState({
        m: res.data.core_latest_ledger,
      });
    })
    .catch((err) => {
      this.setState({ m: "0" });
    });
    //  获取uuid
    axios
.get("/node-selection-stats?uuid=938e03f1-9bb5-4aae-ac2d-ab473cb7e30c")
    .then((res) => {
      
      this.setState({
        uam: JSON.stringify(res.data.stats.date_added),
        usm: JSON.stringify(res.data.stats.user_start_date),

      });
        this.setState({
          uzm: JSON.stringify(res.data.stats.availability),

        });

    })
    .catch((err) => {
      this.setState({ uam: "无效uuid号" });
    });
    //账号12高度xa
    axios
    .get("http://43.153.59.35:31401")
    .then((res) => {
      console.log(res.data.core_latest_ledger);
      this.setState({
        xa: res.data.core_latest_ledger,
      });
    })
    .catch((err) => {
      this.setState({ xa: "0" });
    });
    //  获取uuid
    axios
.get("/node-selection-stats?uuid=fa990829-cba4-4aae-a663-4c457d05c35d")
    .then((res) => {
      
      this.setState({
        uaxa: JSON.stringify(res.data.stats.date_added),
        usxa: JSON.stringify(res.data.stats.user_start_date),

      });
        this.setState({
          uzxa: JSON.stringify(res.data.stats.availability),

        });

    })
    .catch((err) => {
      this.setState({ uaxa: "无效uuid号" });
    });
    // //账号9高度i
    // axios
    //   .get("http://43.156.231.195:31401")
    //   .then((res) => {
    //     console.log(res.data.core_latest_ledger);
    //     this.setState({
    //       i: res.data.core_latest_ledger,
    //     });
    //   })
    //   .catch((err) => {
    //     this.setState({ i: "0" });
    //   });
    // //账号10高度j
    // axios
    //   .get("http://119.28.250.113:31401")
    //   .then((res) => {
    //     console.log(res.data.core_latest_ledger);
    //     this.setState({
    //       j: res.data.core_latest_ledger,
    //     });
    //   })
    //   .catch((err) => {
    //     this.setState({ j: "0" });
    //   });
    // //账号10高度k
    // axios
    //   .get("http://119.28.250.113:31401")
    //   .then((res) => {
    //     console.log(res.data.core_latest_ledger);
    //     this.setState({
    //       k: res.data.core_latest_ledger,
    //     });
    //   })
    //   .catch((err) => {
    //     this.setState({ k: "0" });
    //   });
  }
  render() {
 const handleSearch = (selectedKeys, confirm, dataIndex) => {
      confirm();
      this.setState({searchText:selectedKeys[0]});
      this.setState({searchedColumn:dataIndex});
    }
    const handleReset = (clearFilters) => {
      clearFilters();
      this.setState({searchText:""});
    };
    const getColumnSearchProps = (dataIndex) => ({
      filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters, close }) => (
        <div
          style={{
            padding: 8,
          }}
          onKeyDown={(e) => e.stopPropagation()}
        >
          <Input
            ref={this.searchInput}
            placeholder={`Search ${dataIndex}`}
            value={selectedKeys[0]}
            onChange={(e) => setSelectedKeys(e.target.value ? [e.target.value] : [])}
            onPressEnter={() => handleSearch(selectedKeys, confirm, dataIndex)}
            style={{
              marginBottom: 8,
              display: 'block',
            }}
          />
          <Space>
            <Button
              type="primary"
              onClick={() => handleSearch(selectedKeys, confirm, dataIndex)}
              icon={<SearchOutlined />}
              size="small"
              style={{
                width: 90,
              }}
            >
             搜索
            </Button>
            <Button
              onClick={() => clearFilters && handleReset(clearFilters)}
              size="small"
              style={{
                width: 90,
              }}
            >
             重置
            </Button>
            <Button
              type="link"
              size="small"
              onClick={() => {
                confirm({
                  closeDropdown: false,
                });
                this.setState({searchText:selectedKeys[0]});
               this.setState({searchedColumn:dataIndex});
               
              }}
            >
            恢复
            </Button>
            <Button
              type="link"
              size="small"
              onClick={() => {
                close();
              }}
            >
             关闭
            </Button>
          </Space>
        </div>
      ),
      filterIcon: (filtered) => (
        <SearchOutlined
          style={{
            color: filtered ? '#1677ff' : undefined,
          }}
        />
      ),
      onFilter: (value, record) =>
        record[dataIndex].toString().toLowerCase().includes(value.toLowerCase()),
      onFilterDropdownOpenChange: (visible) => {
        if (visible) {
          setTimeout(() => this.searchInput.current?.select(), 100);
        }
      },
      render: (text) =>
        this.state.searchedColumn === dataIndex ? (
          <Highlighter
            highlightStyle={{
              backgroundColor: '#ffc069',
              padding: 0,
            }}
            searchWords={[this.state.searchText]}
            autoEscape
            textToHighlight={text ? text.toString() : ''}
          />
        ) : (
          text
        ),
    });
  
    const dataSource = [
      {
        key: "1",
        name: " 李淑元",
        address: this.state.a,
        differ: this.state.a - this.state.a,
        todesk:'769 663 858',
        ip: (
          <a href="http://43.153.68.26:31401" target="_blank">
            43.153.68.26
          </a>
        ),
        uuid: (
          <a href="https://sync.minepi.com/node-selection-stats?uuid=cc0701c3-7749-42b9-8c63-8c1a4fb5d8cd" target="_blank">
cc0701c3-7749-42b9-8c63-8c1a4fb5d8cd
          </a>
          
        ),
        zxl: this.state.uzb*100,
        stt: this.state.usb,
        add: this.state.uab,
        des: "云服务器美国",
      },
      {
        key: "2",
        name: "王永辉",
        address: this.state.b,
        differ: this.state.a - this.state.b,
        todesk:'427 086 322',
        ip: (
          <a href="http://43.135.166.80:31401" target="_blank">
           43.135.166.80
          </a>
        ),
        des: "云服务器美国",
      },
      {
        key: "3",
        name: "温州徐总-7",
        address: this.state.d,
        differ: this.state.a - this.state.d,
        todesk:'472 805 239',
        ip: (
          <a href="http://170.106.194.145:31401" target="_blank">
           170.106.194.145
          </a>
        ),
        des: "云服务器美国",
      },
      {
        key: "4",
        name: "洋洋4",
        address: this.state.c,
        differ: this.state.a - this.state.c,
        todesk:'368 060 559',
        ip: (
          <a href="http://43.153.79.135:31401" target="_blank">
           43.153.79.135
          </a>
        ),
        des: "云服务器美国",
      },
      {
        key: "5",
        name: "洋洋3",
        address: this.state.e,
        differ: this.state.a - this.state.e,
        todesk:'200 603 008',
        ip: (
          <a href="http://43.153.120.159:31401" target="_blank">
            43.153.120.159
          </a>
        ),
        des: "云服务器美国",
      },
      {
        key: "6",
        name: "张泥1",
        address: this.state.f,
        differ: this.state.a - this.state.f,
        todesk:'772 783 338',
        ip: (
          <a href="http://43.153.15.235:31401" target="_blank">
          43.153.15.235
          </a>
        ),
        des: "云服务器美国",
      },
      {
        key: "7",
        name: "张泥2",
        address: this.state.g,
        differ: this.state.a - this.state.g,
        todesk:'612 420 815',
        ip: (
          <a href="http://43.135.153.93:31401" target="_blank">
           43.135.153.93
          </a>
        ),
        des: "云服务器美国",
      },
      {
        key: "8",
        name: "马哥6",
        address: this.state.h,
        differ: this.state.a - this.state.h,
        todesk:'352911367',
        ip: (
          <a href="http://43.156.17.19831401" target="_blank">
          43.156.17.198
          </a>
          
        ),
       uuid: (
          <a href="https://sync.minepi.com/node-selection-stats?uuid=cc0701c3-7749-42b9-8c63-8c1a4fb5d8cd" target="_blank">
cc0701c3-7749-42b9-8c63-8c1a4fb5d8cd
          </a>
          
        ),
        zxl: this.state.uza*100,

        stt: this.state.usa,
        add: this.state.uaa,
        des: "云服务器美国",
      },
      {
        key: "9",
        name: "张雷雨",
        address: this.state.i,
        differ: this.state.a - this.state.i,
        todesk:'576 274 477',
        ip: (
          <a href="http://129.226.90.234:31401" target="_blank">
         129.226.90.234
          </a>
          
        ),
       uuid: (
          <a href="https://sync.minepi.com/node-selection-stats?uuid=ec2b1ac8-347a-465d-8ae2-4a4e71c240ed" target="_blank">
ec2b1ac8-347a-465d-8ae2-4a4e71c240ed
          </a>
          
        ),
        stt: this.state.usc,
        add: this.state.uac,
       
zxl: this.state.uzc*100,

        des: "云服务器新加坡",
      },
      {
        key: "10",
        name: "王心关",
        address: this.state.k,
        differ: this.state.a - this.state.k,
        todesk:'820 135 507',
        ip: (
          <a href="http://43.153.114.43:31401" target="_blank">
        43.153.114.43
          </a>
          
        ),
       uuid: (
          <a href="https://sync.minepi.com/node-selection-stats?uuid=dcb75a14-23d0-4522-b395-99115127529c" target="_blank">
ec2b1ac8-347a-465d-8ae2-4a4e71c240ed
          </a>
          
        ),
        stt: this.state.usd,
        add: this.state.uad,
       
zxl: this.state.uzd*100,

        des: "云服务器美国",
      },
      {
        key: "11",
        name: "黄光兰",
        address: this.state.m,
        differ: this.state.a - this.state.m,
        todesk:'546 724 730',
        ip: (
          <a href="http://43.153.49.98:31401" target="_blank">
       43.153.49.98
          </a>
          
        ),
       uuid: (
          <a href="https://sync.minepi.com/node-selection-stats?uuid=938e03f1-9bb5-4aae-ac2d-ab473cb7e30c" target="_blank">
938e03f1-9bb5-4aae-ac2d-ab473cb7e30c
          </a>
          
        ),
        stt: this.state.usm,
        add: this.state.uam,
       
zxl: this.state.uzm*100,

        des: "云服务器美国",
      },
      {
        key: "12",
        name: "朱章",
        address: this.state.xa,
        differ: this.state.a - this.state.xa,
        todesk:'181 616 550',
        ip: (
          <a href="http://43.153.59.35:31401" target="_blank">
      43.153.59.35
          </a>
          
        ),
       uuid: (
          <a href="https://sync.minepi.com/node-selection-stats?uuid=fa990829-cba4-4aae-a663-4c457d05c35d" target="_blank">
fa990829-cba4-4aae-a663-4c457d05c35d
          </a>
          
        ),
        stt: this.state.usxa,
        add: this.state.uaxa,
       
zxl: this.state.uzxa*100,

        des: "云服务器美国",
      },
    //   {
    //     key: "9",
    //     name: " 叶凤华3",
    //     address: this.state.i,
    //     differ: this.state.a - this.state.i,
    //     todesk:'397 577 821',
    //     ip: (
    //       <a href="http://43.156.231.195:31401" target="_blank">
    //         43.156.231.195
    //       </a>
    //     ),
    //     des: "云服务器新加坡",
    //   },
    //   {
    //     key: "10",
    //     name: " 刘爱绿4",
    //     address: this.state.j,
    //     differ: this.state.a - this.state.j,
    //     todesk:'495 024 351',
    //     ip: (
    //       <a href="http://119.28.250.113:31401" target="_blank">
    //         119.28.250.113
    //       </a>
    //     ),
    //     des: <font color='red'>云服务器孟买</font>,
    //   },
    //   {
    //     key: "11",
    //     name: "沈信义5",
    //     address: this.state.j,
    //     differ: this.state.a - this.state.j,
    //     todesk:'910 610 767',
    //     ip: (
    //       <a href="http://119.28.250.113:31401" target="_blank">
    //        119.28.250.113
    //       </a>
    //     ),
    //     des: <font color='red'>云服务器孟买</font>,
    //   },
    ];
    const columns = [
      {
        title: "业主名字",
        dataIndex: "name",
        key: "name",
         ...getColumnSearchProps('name'),
      },
      {
        title: "区块高度",
        dataIndex: "address",
        key: "address",
      },
      {
        title: "区块延迟数值",
        dataIndex: "differ",
        key: "differ",
        sorter: {
      compare: (a, b) => a.differ - b.differ,
      multiple: 3,
    },
      },
      {
        title: "todesk",
        dataIndex: "todesk",
        key: "todesk",
         ...getColumnSearchProps('todesk'),
      },
      {
        title: "云服务器ip地址",
        dataIndex: "ip",
        key: "ip",
      },
      {
        title: "uuid",
        dataIndex: "uuid",
        key: "uuid",
      },
      {
        title: "开始时间",
        dataIndex: "stt",
        key: "stt",
      },
      {
        title: "最后一次时间",
        dataIndex: "add",
        key: "add",
      },
      {
        title: "在线率百分之",
        dataIndex: "zxl",
        key: "zxl",
      },
      {
        title: "云服务器地区",
        dataIndex: "des",
        key: "des",
      },
    ];
    return (
      <div>
       
        <center><font size="18" color="red">
        随升客户节点区块高度
        </font></center>
        <Table dataSource={dataSource} columns={columns} />;
      </div>
    );
  }
}

export default SuiS;
